﻿using System;
using System.Windows.Forms;

namespace hello_accinv_New_
{
    public partial class LogForm : Form
    {
        private Database db;

        public LogForm()
        {
            InitializeComponent();

            db = new Database();

            radioToday.Text = "Today (" + DateTime.Today.ToLongDateString() + ")";

            dateTimePicker.MaxDate = DateTime.Today;
        }

        private void radioSelectDate_CheckedChanged(object sender, EventArgs e)
        {
            if (radioSelectedDate.Checked)
            {
                dateTimePicker.Enabled = true;

                LoadLog(dateTimePicker.Value);
            }
        }

        private void radioToday_CheckedChanged(object sender, EventArgs e)
        {
            if (radioToday.Checked)
            {
                dateTimePicker.Enabled = false;

                LoadLog(DateTime.Today);
            }
        }

        private void LoadLog(DateTime selectedDate)
        {
            dataGridView.DataSource = db.Select("*", "ActionLog", "Date = '" + CustomDateTime.ToSqlDate(selectedDate) + "'");
            Console.WriteLine(CustomDateTime.ToSqlDate(selectedDate));
            dataGridView.ClearSelection();
        }

        private void dateTimePicker_ValueChanged(object sender, EventArgs e)
        {
            LoadLog(dateTimePicker.Value);
        }
    }
}
